#usr/bin/python
from os import listdir
import os.path, codecs
from xml import make_documentation

htmlStructure = u'''
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Symbide/%s</title>
<link rel="stylesheet" type="text/css" href="stylesheets/basic.css">
<link rel="stylesheet" type="text/css" href="stylesheets/documentation.css">
</head>
<body>
<!--banner-->
%s

<!--body-->
%s

</body>
</html>'''

bannerFile = codecs.open("xml/banner.xml", "r", 'utf-8')
banner = bannerFile.read()
bannerFile.close()

for xmlFile in listdir('xml'):
    if xmlFile.find('body_')!=0 or xmlFile[-1]=='~' or xmlFile[-4:]!='.xml':
        continue
    
    bodyFile = codecs.open(os.path.join('xml', xmlFile), 'r', 'utf-8')
    body = bodyFile.read()
    bodyFile.close()
    
    name = os.path.splitext(xmlFile)[0].replace('body_', '', 1)
    
    f = codecs.open(os.path.join('html', name+'.html'), 'w', 'ISO-8859-1')
    f.write(htmlStructure%(name.capitalize(), banner, body))
    f.close()
        
        
